# -*- encoding: utf-8 -*-
"""
字符串常用库
@File    : strutils.py
@Time    : 2020/12/4 10:39
@Author  : wp
@Email   : wangpeng99@picc.com.cn
@Software: PyCharm
"""


def strQ2B(ustring):
    """全角转半角"""
    rstring = ""
    for uchar in ustring:
        inside_code = ord(uchar)
        if inside_code == 12288:  # 全角空格直接转换
            inside_code = 32
        elif (inside_code >= 65281 and inside_code <= 65374):  # 全角字符（除空格）根据关系转化
            inside_code -= 65248

        rstring += chr(inside_code)
    return rstring


def strB2Q(ustring):
    """半角转全角"""
    rstring = ""
    for uchar in ustring:
        inside_code = ord(uchar)
        if inside_code == 32:  # 半角空格直接转化
            inside_code = 12288
        elif inside_code >= 32 and inside_code <= 126:  # 半角字符（除空格）根据关系转化
            inside_code += 65248

        rstring += chr(inside_code)
    return rstring


if __name__ == '__main__':
    aa=strQ2B("用户中心-用户认证（E端和B端）微服务")
    print(aa)